namespace ClassyBlog.Infrastructure
{
    using System;
    using System.Web.Mvc;

    public class DefaultViewPageActivator : IViewPageActivator
    {
        public object Create(ControllerContext controllerContext, Type type)
        {
            var view = DependencyResolver.Current.GetService(type) ??
                       Activator.CreateInstance(type);

            var hasRenderer = view as IHasRenderer;

            if (hasRenderer != null)
            {
                hasRenderer.SetRenderer(
                    DependencyResolver.Current.GetService<IRenderer>());
            }

            return view;
        }
    }
}